package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;
import com.common.lib.constant.Constants;
import com.common.lib.fragment.BaseFragment;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.thinkfit.jy.R;
import com.thinkfit.jy.activity.ApplicationActivity;
import com.thinkfit.jy.activity.FreeMovementActivity;
import com.thinkfit.jy.activity.LoginActivity;
import com.thinkfit.jy.activity.SettingActivity;
import com.thinkfit.jy.activity.TVActivity;
import com.thinkfit.jy.activity.UserProfileActivity;
import com.thinkfit.jy.activity.VideoActivity;
import com.thinkfit.jy.serialport.SerialPortManager;
import com.thinkfit.jy.utils.BluetoothOrder;
import com.thinkfit.jy.utils.FastBlurUtility;
import com.thinkfit.jy.utils.MotionDataUtils;

/**
 * 奥迪风格主题首页菜单界面
 */
public class HomeADFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {

    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home_ad;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        init();
    }

    protected void init() {
        setViewsOnClickListener(R.id.flUserCenter, R.id.flSetting,
                R.id.flFastStart, R.id.flVideoCourse, R.id.flLiveVideo, R.id.fl3DCourse,
                R.id.flApplication, R.id.flSport, R.id.flTv);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.flUserCenter:
                if (DataManager.Companion.getInstance().getMainStyle() == 3) {
                    DataManager.Companion.getInstance().setObject(FastBlurUtility.getBlurBackgroundDrawer(getActivity()));
                }
                if (DataManager.Companion.getInstance().getMyInfo() == null) {
                    showToast(R.string.app_please_login_first);
                    openActivity(LoginActivity.class);
                    return;
                }
                openActivity(UserProfileActivity.class);
                break;
            case R.id.flSetting:
                if (DataManager.Companion.getInstance().getMainStyle() == 3) {
                    DataManager.Companion.getInstance().setObject(FastBlurUtility.getBlurBackgroundDrawer(getActivity()));
                }
                openActivity(SettingActivity.class);
                break;
            case R.id.flVideoCourse:
                Bundle bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA, 1);
                openActivity(VideoActivity.class, bundle);
                break;
            case R.id.fl3DCourse://3D课程
                ToastUtils.showShort(getString(R.string.app_toast_hint_2));
                break;
            case R.id.flSport:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA, 0);
                openActivity(FreeMovementActivity.class, bundle);
                break;
            case R.id.flLiveVideo:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA, 4);
                openActivity(VideoActivity.class, bundle);
                break;
            case R.id.flApplication:
                openActivity(ApplicationActivity.class);
                break;
            case R.id.flTv:
                openActivity(TVActivity.class);
                break;
            case R.id.flFastStart:
                if (!SerialPortManager.getInstance().isConnected()&&!BluetoothOrder.getInstance().isConnect()) {
                    showToast(R.string.app_device_connect);
                    return;
                }
                if (MotionDataUtils.getInstance().isRun()) {
                    SerialPortManager.getInstance().stopRun();
                } else {
                    SerialPortManager.getInstance().startRun();
                    if (DataManager.Companion.getInstance().isLogin()) {
                        bundle = new Bundle();
                        bundle.putInt(Constants.BUNDLE_EXTRA, 1);
                        openActivity(FreeMovementActivity.class, bundle);
                    }
                }
                break;
        }
    }
}
